<template>
  <div>
    <div class="bgc-default pad-20">
      <div class="bg-color-white pad-20">
        <el-steps v-if="afterSale.afterSaleType == 10 || afterSale.afterSaleType == 20" :active="activeNum" class="step-bar div-styls" finish-status="success" align-center>
          <el-step title="申请退货"></el-step>
          <el-step title="审核申请"></el-step>
          <el-step v-if="afterSale.afterSaleType == 10" title="确认退货"></el-step>
          <el-step title="确认退款"></el-step>
          <el-step title="关闭申请"></el-step>
        </el-steps>
        <el-steps v-if="!getSupplierId() && !getWarehouseId() && afterSale.afterSaleType == 30" :active="activeNum" class="step-bar div-styls" finish-status="success" align-center>
          <el-step title="申请退货"></el-step>
          <el-step title="确认退款"></el-step>
          <el-step title="关闭申请"></el-step>
        </el-steps>
        <el-steps v-if="(getSupplierId() || getWarehouseId()) && afterSale.afterSaleType == 30" :active="activeNum" class="step-bar div-styls" finish-status="success" align-center>
          <el-step title="买家取消"></el-step>
          <el-step title="审核申请"></el-step>
        </el-steps>
      </div>
    </div>
    <div class="bgc-default pad-l-20 pad-r-20 pad-b-20">
      <div>
        <el-row :gutter="20">
          <el-col :span="8">
            <div class="bg-color-white">
              <div class="title-top flex v-align-c flex-center height-44 pad-l-27 pad-r-27">
                <div class="flex-item font-w font-16">申请信息</div>
              </div>
              <div class="pad-t-15 pad-b-15 pad-l-30 pad-r-10 mar-l-30 mar-r-10 buyer-info-line">
                <div class="flex">
                  <div class="font-color-9 width-100">退货申请单号：</div>
                  <div class="flex-item">
                    {{ afterSale.afterSaleNo ||  '&nbsp;' }}
                    <a href="javascript:;" @click="handleClipboard(afterSale.afterSaleNo, $event)"><span class="mar-l-10 font-blue">复制</span></a>
                  </div>
                </div>
                <div class="flex">
                  <div class="font-color-9 width-100">退货申请类型：</div>
                  <div class="flex-item">{{ dict.afterSaleType[afterSale.afterSaleType] ||  '&nbsp;' }}</div>
                </div>
                <div class="flex">
                  <div class="font-color-9 width-100">退货原因：</div>
                  <div class="flex-item">{{ afterSaleReasonMap[afterSale.afterSaleReasonId] ? afterSaleReasonMap[afterSale.afterSaleReasonId].cancelReason : '' }}&nbsp;</div>
                </div>
                <div class="flex">
                  <div class="font-color-9 width-100">买家信息：</div>
                  <div class="flex-item">{{ afterSale.customerNickname ||  '&nbsp;' }}<span v-if="afterSale.customerPhone">(手机号:{{afterSale.customerPhone}})</span>&nbsp;</div>
                </div>
                <div class="flex">
                  <div class="font-color-9 width-100">退货说明：</div>
                  <div class="flex-item">{{ afterSale.customerRemark ||  '&nbsp;' }}&nbsp;</div>
                </div>
                <div class="flex">
                  <div class="font-color-9 width-100">退货凭证：</div>
                  <div class="flex-item">
                    <img v-for="(image, index) in afterSale.imageList" :key="index" :src="image.imageUrl" height="50" @click="showImage(image.imageUrl)">
                  </div>
                </div>
                <!-- <div class="flex" v-if="!isGroupBuyOrder">
                  <div class="font-color-9 width-100">退货快递名称：</div>
                  <div class="flex-item">{{ afterSale.expressName ||  '&nbsp;' }}</div>
                </div>
                <div class="flex" v-if="!isGroupBuyOrder">
                  <div class="font-color-9 width-100">退货快递单号：</div>
                  <div class="flex-item">
                    <span v-if="afterSale.trackingNo">
                      {{ afterSale.trackingNo }}
                    </span>&nbsp;
                    <a href="javascript:;" v-if="afterSale.afterSaleStatus == 0" @click="showExpress"><span class="mar-l-10 font-blue">编辑</span></a>
                    <a href="javascript:;" v-if="afterSale.trackingNo" @click="handleClipboard(afterSale.trackingNo, $event)"><span class="mar-l-10 font-blue">复制单号</span></a>
                  </div>
                </div> -->
              </div>
            </div>
          </el-col>
          <el-col :span="8">
            <div class="bg-color-white">
              <div class="title-top flex v-align-c flex-center height-44 pad-l-27 pad-r-27">
                <div class="flex-item font-w font-16">其他信息</div>
              </div>
              <div class="pad-t-15 pad-b-15 pad-l-30 pad-r-10 mar-l-30 mar-r-10 buyer-info-line">
                <div class="flex">
                  <div class="font-color-9 width-100">关联订单号：</div>
                  <div class="flex-item">
                    <span class="font-blue" @click="goOrderDetail">{{afterSale.orderNo}}</span>&nbsp;
                    <a href="javascript:;" @click="handleClipboard(afterSale.orderNo, $event)"><span class="mar-l-10 font-blue">复制</span></a>
                  </div>
                </div>
                <div class="flex" v-if="isComDeliveryNo">
                  <div class="font-color-9 width-100">配送单号：</div>
                  <div class="flex-item">
                    <span>{{afterSale.projectOrder.deliveryNo}}</span>
                  </div>
                </div>
                <div class="flex">
                  <div class="font-color-9 width-100">关联订单类型：</div>
                  <div class="flex-item" v-if="!isGroupBuyOrder">{{ dict.orderType[afterSale.orderType] || '&nbsp;' }}</div>
                  <div class="flex-item" v-if="isGroupBuyOrder">社区团购订单</div>
                </div>
                <div class="flex">
                  <div class="font-color-9 width-100">关联订单状态：</div>
                  <div class="flex-item" v-if="afterSale.projectOrder && !isGroupBuyOrder">{{ dict.orderStatus[afterSale.projectOrder.orderStatus] ||  '&nbsp;' }}</div>
                   <div class="flex-item" v-if="afterSale.projectOrder && isGroupBuyOrder">{{ dict.villageOrderStatus[afterSale.projectOrder.orderStatus] ||  '&nbsp;' }}</div>
                </div>
                <div class="flex">
                  <div class="font-color-9 width-100">申请时间：</div>
                  <div class="flex-item">{{ afterSale.createTime ||  '&nbsp;' }}</div>
                </div>
                <div class="flex">
                  <div class="font-color-9 width-100">审核时间：</div>
                  <div class="flex-item">{{ afterSale.auditTime ||  '&nbsp;' }}</div>
                </div>
                <div class="flex">
                  <div class="font-color-9 width-100">确认时间：</div>
                  <div class="flex-item">{{ afterSale.refundGoodsTime ||  '&nbsp;' }}</div>
                </div>
                <div class="flex">
                  <div class="font-color-9 width-100">完成时间：</div>
                  <div class="flex-item">{{ afterSale.completedTime ||  '&nbsp;' }}</div>
                </div>
                <div class="flex" v-if="!getSupplierId() && !getWarehouseId()">
                  <div class="font-color-9 width-100">企业备注：</div>
                  <div class="flex-item">
                    <span v-if="afterSale.enterpriseRemark">
                      {{ afterSale.enterpriseRemark }}
                    </span>&nbsp;
                    <a v-if="afterSale.afterSaleStatus != 3 && afterSale.afterSaleStatus != 4" href="javascript:;" @click="editEnterpriseRemark"><span class="mar-l-10 font-blue">编辑备注</span></a>
                  </div>
                </div>
                <div class="flex" v-if="afterSale.afterSaleGoodsList[0].source != 30 && !isGroupBuyOrder">
                  <div class="font-color-9 width-100">供应商备注：</div>
                  <div class="flex-item">
                    <span v-if="afterSale.supplierRemark">
                      {{ afterSale.supplierRemark }}
                    </span>&nbsp;
                    <a v-if="afterSale.afterSaleStatus != 3 && afterSale.afterSaleStatus != 4" href="javascript:;" @click="editSupplierRemark"><span class="mar-l-10 font-blue">编辑备注</span></a>
                  </div>
                </div>
              </div>
            </div>
          </el-col>
          <el-col :span="8" v-if="afterSale.afterSaleType == 10 && (afterSale.afterSaleStatus == 1 || 
          afterSale.afterSaleStatus == 2 || afterSale.afterSaleStatus == 3 || afterSale.afterSaleStatus == 4)">
            <div class="bg-color-white">
              <div class="title-top flex v-align-c flex-center height-44 pad-l-27 pad-r-27">
                <div class="flex-item font-w font-16">退货物流</div>
              </div>
              <div class="pad-t-15 pad-b-15 pad-l-30 pad-r-10 mar-l-30 mar-r-10 buyer-info-line">
                <div class="flex">
                  <div class="font-color-9 width-100">物流单号：</div>
                  <div class="flex-item">{{ afterSale.trackingNo ||  '&nbsp;' }}</div>
                </div>
                <div class="flex">
                  <div class="font-color-9 width-100">物流公司：</div>
                  <div class="flex-item">{{ afterSale.expressName ||  '&nbsp;' }}</div>
                </div>
                <div class="flex">
                  <div class="font-color-9 width-100">联系电话：</div>
                  <div class="flex-item">{{ afterSale.refundPhone ||  '&nbsp;' }}</div>
                </div>
              </div>
            </div>
          </el-col>
          <!-- 总部 退款类型: 退货退款 -->
          <el-col :span="8" v-if="(!getSupplierId() && !getWarehouseId()) && afterSale.afterSaleType == 10 && enableAfterSaleWarehouse">
            <div class="bg-color-white">
              <div class="title-top flex v-align-c flex-center height-44 pad-l-27 pad-r-27">
                <div class="flex-item font-w font-16">退货地址</div>
                <!-- 修改退货地址目前与3.9.5新增的退货仓逻辑冲突(退货仓读取的是退货仓的地址,而用户又去修改地址,这时候是读取哪一个地址),功能先隐藏 -->
                <!-- <a class="float-r" href="javascript:;" @click="showAddress" v-if="afterSale.afterSaleStatus == 0 && afterSale.goodsList[0].source != 30">修改退货地址</a> -->
                <a class="float-r font-blue" href="javascript:;" @click="showAfterSaleWarehouse" v-if="afterSale.initAfterSaleWarehouse == 0 && afterSale.afterSaleStatus == 0 && afterSale.afterSaleGoodsList[0].source != 30">修改退货仓</a>&nbsp;&nbsp;&nbsp;
                <a class="float-r font-blue" href="javascript:;" @click="confirmAfterSaleWarehouse" v-if="afterSale.initAfterSaleWarehouse == 0 && afterSale.afterSaleStatus == 0 && afterSale.afterSaleGoodsList[0].source != 30">确认退货仓</a>
              </div>
              <div class="pad-t-15 pad-b-15 pad-l-30 pad-r-10 mar-l-30 mar-r-10 buyer-info-line">
                <div class="flex">
                  <div class="font-color-9 width-120">退货仓确认状态：</div>
                  <div class="flex-item">{{ afterSale.initAfterSaleWarehouse == 0 ? '未确认' : '已确认' }}</div>
                </div>
                <div class="flex">
                  <div class="font-color-9 width-100">退货仓：</div>
                  <div class="flex-item">{{ afterSale.afterSaleWarehouseName || afterSale.afterSaleWarehouseName }}</div>
                </div>
                <div class="flex">
                  <div class="font-color-9 width-100">收件人：</div>
                  <div class="flex-item">{{ dialogWarehouseForm.receiveName }}</div>
                </div>
                <div class="flex">
                  <div class="font-color-9 width-100">联系电话：</div>
                  <div class="flex-item">{{ dialogWarehouseForm.receivePhone }}</div>
                </div>
                <div class="flex">
                  <div class="font-color-9 width-100">详细地址：</div>
                  <div class="flex-item">{{ dialogWarehouseForm.warehouseDetailAddress }}</div>
                </div>
              </div>
            </div>
          </el-col>
        </el-row>
        <div class="pad-b-10" v-if="(getSupplierId() || getWarehouseId()) && afterSale.afterSaleType == 10 && !isGroupBuyOrder">
          <div class="border-b pad-t-10 pad-b-2 font-w font-15 font-blue">
            <span>退货地址</span>
            <!-- 修改退货地址目前与3.9.5新增的退货仓逻辑冲突(退货仓读取的是退货仓的地址,而用户又去修改地址,这时候是读取哪一个地址),功能先隐藏 -->
            <!-- <a class="float-r" href="javascript:;" @click="showAddress" v-if="afterSale.afterSaleStatus == 0 && afterSale.goodsList[0].source != 30">修改退货地址</a> -->
          </div>
          <div>
            <el-row>
              <el-col :span="2" class="align-r pad-r-10"> 收件人：</el-col>
              <el-col :span="10">
                {{ dialogWarehouseForm.receiveName }}
              </el-col>
              <el-col :span="2" class="align-r pad-r-10"> 联系电话：</el-col>
              <el-col :span="10">
                {{ dialogWarehouseForm.receivePhone }}
              </el-col>
              <el-col :span="2" class="align-r pad-r-10"> 详细地址：</el-col>
              <el-col :span="10">
                {{ dialogWarehouseForm.warehouseDetailAddress }}
              </el-col>
            </el-row>
          </div>
        </div>
      </div>
    </div>
    <div class="bgc-default pad-l-20 pad-r-20 pad-b-20">
      <div class="bg-color-white pad-l-20 pad-r-20 pad-b-20 pad-t-10">
        <div class="tabs-box">
          <el-tabs value="goodsInfo">
            <el-tab-pane label="退货商品信息" name="goodsInfo" class="mar-t-15">
              <el-table ref="multipleTable" :data="afterSaleGoodsList" style="width: 100%" class="last-none-border">
                <el-table-column min-width="280px" label="商品名称" prop="goodsTitle">
                  <template slot-scope="scope">
                    <div class="flex v-align-c cursor-p">
                      <label v-if="scope.row.goodsImageUrl"><img :src="scope.row.goodsImageUrl" class="mini-pic"></label>
                      <div v-if="scope.row.goodsTitle" class="font-12 pad-l-10">
                        <div>{{scope.row.goodsTitle}}</div>
                      </div>
                    </div>
                  </template>
                </el-table-column>
                <el-table-column width="180px" label="商品规格" prop="skuDetail" align="center">
                  <template slot-scope="scope">
                    <div class="font-blue">
                      {{!scope.row.skuDetail ? '无' : scope.row.skuDetail}}
                    </div>
                  </template>
                </el-table-column>
                <el-table-column width="175px" label="发货方" prop="supplierName" align="center">
                  <template slot-scope="scope">
                    <div>
                      {{scope.row.supplierName || '总部'}}
                      <br/>({{ scope.row.auditStatus == 1 ? '待审核' : scope.row.auditStatus == 2 ? '已同意' : '未同意' }})
                      <el-tooltip class="item" effect="dark" :content="afterSale.rejectReason" placement="right">
                        <i class="el-icon-question" v-if="scope.row.auditStatus == 3"></i>
                      </el-tooltip>
                    </div>
                  </template>
                </el-table-column>
                <el-table-column width="175px" label="仓库" prop="supplierName" align="center">
                  <template slot-scope="scope">
                    <div>
                      {{ scope.row.warehouseId ? scope.row.warehouseName : '未开启仓库' }}
                    </div>
                  </template>
                </el-table-column>
                <el-table-column width="135px" label="供应价" prop="goodsSupplyPrice" align="center">
                  <template slot-scope="scope">
                    <div v-if="scope.row.goodsSupplyPrice">
                      <div>￥{{scope.row.goodsSupplyPrice}}</div>
                    </div>
                  </template>
                </el-table-column>
                <el-table-column width="135px" label="销售价格" prop="goodsPrice" align="center">
                  <template slot-scope="scope">
                    <div v-if="scope.row.goodsPrice">
                      <div>￥{{scope.row.goodsPrice}}</div>
                    </div>
                  </template>
                </el-table-column>
                <el-table-column width="135px" label="税额" prop="goodsRefundTax" align="center">
                  <template slot-scope="scope">
                    <div v-if="scope.row.goodsRefundTax">
                      <div>￥{{scope.row.goodsRefundTax}}</div>
                    </div>
                  </template>
                </el-table-column>
                <el-table-column width="135px" label="退货数量（件）" prop="goodsNum" align="center">
                  <template slot-scope="scope">
                    <div v-if="scope.row.goodsNum">
                      <div>{{scope.row.goodsNum}}件</div>
                    </div>
                  </template>
                </el-table-column>
                <!-- 退货退款  -->
                <el-table-column width="135px" label="入库数量（件）" prop="goodsNum" align="center" v-if="afterSale.afterSaleType == 10">
                  <template slot-scope="scope">
                    <div>
                      {{scope.row.inWarehouseNum}} 件
                      <!-- <a href="javascript:;" v-if="scope.row.inWarehouseFlag == 1" @click="editInWarehouseNumDialog(scope.row.afterSaleGoodsId, scope.row.goodsNum)"><span class="mar-l-10 font-blue">编辑</span></a> -->
                    </div>
                  </template>
                </el-table-column>
                <el-table-column width="135px" label="退货金额（元）" align="center">
                  <template slot-scope="scope">
                    <div v-if="afterSale.afterSaleType == 30 || afterSale.afterSaleStatus == 3 || afterSale.afterSaleStatus == 4 || getSupplierId()">
                      {{scope.row.goodsRefundMoney}}
                    </div>
                    <el-input v-if="afterSale.afterSaleType != 30 && afterSale.afterSaleStatus != 3 && afterSale.afterSaleStatus != 4 && !getSupplierId()" class="width-100"  v-model="scope.row.goodsRefundMoney"  @keyup.native="totalRefundGoodsAmount()" size="mini"></el-input>
                  </template>
                </el-table-column>
              </el-table>
              <div class="pad-t-20 pad-b-20" style="background-color: #F3FBFE;" v-if="!getSupplierId()">
                <el-row>
                  <el-col :span="2" class="align-r pad-r-10"> 商品退货金额：</el-col>
                  <el-col :span="10">
                    <div v-if="afterSale.refundGoodsAmount">{{ afterSale.refundGoodsAmount }}元</div>&nbsp;
                  </el-col>
                  <el-col :span="2" class="align-r pad-r-10" v-if="!isGroupBuyOrder"> 邮费退款金额：</el-col>
                  <el-col :span="10" v-if="!isGroupBuyOrder">
                    <div v-if="afterSale.afterSaleStatus == 3 || afterSale.afterSaleStatus == 4">{{ afterSale.freightAmount }}元</div>&nbsp;
                    <el-input v-if="afterSale.afterSaleStatus != 3 && afterSale.afterSaleStatus != 4" class="width-200" v-model="afterSale.freightAmount" @blur="checkFreightAmount(afterSale.freightAmount)" size="mini"><template slot="append">元</template></el-input>
                    <div v-if="afterSale.afterSaleStatus != 3 && afterSale.afterSaleStatus != 4" class="pad-t-10">请根据与顾客协商结果调整邮费退款金额。当前剩余可退运费{{ afterSale.surplusFreightAmount }}元</div>
                  </el-col>
                  <el-col :span="2" class="align-r pad-r-10 font-w font-16">合计退款金额：</el-col>
                  <el-col :span="10">
                    <div>{{((afterSale.refundGoodsAmount || 0) * 1 + (afterSale.freightAmount || 0) * 1).toFixed(2)}}元</div>
                  </el-col>
                </el-row>
              </div>
              <div v-if="!getSupplierId() && !getWarehouseId()" class="pad-l-16 pad-t-10">退款方式：原路退回</div>
            </el-tab-pane>
            <el-tab-pane label="操作信息" name="logInfo" v-if="!getSupplierId()"  class="mar-t-15">
              <el-table  ref="multipleTable" :data="logList" style="width: 100%" class="action-table">
                <el-table-column min-width="350px" label="操作内容" prop="operatorContent"></el-table-column>
                <el-table-column width="150px" label="操作人" prop="operatorName"></el-table-column>
                <el-table-column width="180px" label="操作时间" prop="createTime"></el-table-column>
              </el-table>
            </el-tab-pane>
          </el-tabs>
        </div>
      </div>

      <div class="height-70"></div>
      <div class="bottom-bar" v-if="!isComDeliveryNo">
        <!-- 淘宝联盟的单暂时不处理 -->
        <el-button type="primary" v-if="agreeButtonShow" @click="agreeAfterSale">
          同意申请
        </el-button>
        <el-button type="primary" v-if="agreeRefundGoodsInButtonShow" @click="agreeRefundGoodsAndGoodsIn">
          商品入库，同意退款
        </el-button>
        <el-button type="primary" v-if="agreeRefundGoodsNotInButtonShow" @click="disAgreeRefundGoodsAndGoodsIn">
          商品不入库，同意退款
        </el-button>
        <el-button type="primary" v-if="agreeRefundMoneyShow" @click="agreeRefundMoney">
          确认退款
        </el-button>
        <el-button type="primary" v-if="disAgreeRefundMoneyButton" @click="disAgreeAfterSale">
          不同意退款
        </el-button>
        <el-button type="primary" v-if="disAgreeButtonShow" @click="disAgreeAfterSale">
          不同意申请
        </el-button>
        <el-button @click="goOrderList">返回</el-button>
      </div>
      <div class="bottom-bar" v-else>
        <el-button type="primary" disabled>已生成配送单，无法取消</el-button>
        <el-button @click="goOrderList">返回</el-button>
      </div>

      <el-dialog :title="isDisagree ? '不同意退货/退款' : '修改备注'" :visible.sync="editFormVisible" :close-on-press-escape="true" width="800px">
        <el-form label-position="right" class="pad-30">
          <el-form-item :label-width="isDisagree ? '120px' : '50px'" :label="isDisagree ? '不同意理由' : '备注'" prop="expressName">
            <div><el-input v-model="dialogForm.editText" type="textarea" :rows="3" :placeholder="isDisagree ? '请输入不同意顾客退货理由' : '请输入备注'"></el-input></div>
          </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button @click="cancelEdit">取消</el-button>
          <el-button type="primary" @click="saveEdit" :loading="saveEditLoading">确定</el-button>
        </div>
      </el-dialog>

      <el-dialog title="修改快递" :visible.sync="editExpressVisible" :close-on-press-escape="true" width="800px">
        <el-form label-position="right" class="pad-30" :model="dialogForm" :rules="rules" ref="express">
          <el-form-item label-width="130px" label="退货快递名称：" prop="expressName">
            <div><el-input v-model="dialogForm.expressName" placeholder="请输入快递名称"></el-input></div>
          </el-form-item>
          <el-form-item label-width="130px" label="退货快递单号：" prop="trackingNo" >
            <div><el-input v-model="dialogForm.trackingNo" placeholder="请输入快递单号"></el-input></div>
          </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button @click="editExpressVisible=false">取消</el-button>
          <el-button type="primary" @click="saveExpress">确定</el-button>
        </div>
      </el-dialog>

      <el-dialog title="修改退货地址" :visible.sync="editAddressVisible" :close-on-press-escape="true" width="800px">
        <el-form label-position="right" class="pad-30" :model="dialogForm" :rules="rules" ref="address">
          <el-form-item label-width="130px" label="收件人" prop="receiveName">
            <div><el-input v-model="dialogForm.receiveName" placeholder="请输入收件人名称"></el-input></div>
          </el-form-item>
          <el-form-item label-width="130px" label="联系电话" prop="receivePhone">
            <div><el-input v-model="dialogForm.receivePhone" placeholder="请输入收件人联系电话" maxlength="11"></el-input></div>
          </el-form-item>
          <el-form-item label-width="130px" label="详细地址" prop="receiveAddress">
            <div>
              <el-select v-model="dialogForm.refundProvinceCode" placeholder="省份" @change="changeProvince()">
                <el-option v-for="item in provinceList" :key="item.areaCode" :label="item.areaName" :value="item.areaCode"></el-option>
              </el-select>
              <el-select v-model="dialogForm.refundCityCode" placeholder="城市" @change="changeCity()">
                <el-option v-for="item in cityList" :key="item.areaCode" :label="item.areaName" :value="item.areaCode"></el-option>
              </el-select>
              <el-select v-model="dialogForm.refundDistrictCode" placeholder="地区">
                <el-option v-for="item in districtList" :key="item.areaCode" :label="item.areaName" :value="item.areaCode"></el-option>
              </el-select>
              <el-input v-model="dialogForm.receiveAddress" type="textarea" class="mar-t-10" placeholder="详细地址" />
            </div>
          </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button @click="editAddressVisible=false">取消</el-button>
          <el-button type="primary" @click="saveAddress">确定</el-button>
        </div>
      </el-dialog>

      <el-dialog title="修改退货仓" :visible.sync="editAfterSaleWarehouse" :close-on-press-escape="true" width="800px">
        <el-form label-position="right" class="pad-30" :model="dialogWarehouseForm">
          <el-form-item label-width="130px" label="退货仓">
            <div>
              <el-select v-model="dialogWarehouseForm.afterSaleWarehouseId" placeholder="请选择退货仓" @change="changeAfterSaleWarehouse()" clearable >
                <el-option v-for="item in afterSaleWarehouseList" :key="item.warehouseId" :label="item.warehouseName" :value="item.warehouseId"></el-option>
              </el-select>
            </div>
          </el-form-item>
          <el-form-item label-width="130px" label="收件人">
            <div>{{ dialogWarehouseForm.receiveName }}</div>
          </el-form-item>
          <el-form-item label-width="130px" label="联系电话">
            <div>{{ dialogWarehouseForm.receivePhone }}</div>
          </el-form-item>
          <el-form-item label-width="130px" label="详细地址">
            <div>{{ dialogWarehouseForm.warehouseDetailAddress }}</div>
          </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button @click="editAfterSaleWarehouse=false">取消</el-button>
          <el-button type="primary" @click="saveAfterSaleWarehouse">确定</el-button>
        </div>
      </el-dialog>

      <el-dialog title="修改退货入库数量" :visible.sync="inWarehouseNumDialog" :close-on-press-escape="true" width="800px">
        <el-form label-position="right" class="pad-30" :model="dialogWarehouseForm">
          <el-form-item label-width="130px" label="退货数量">
            <div>{{ editInWarehouseNumForm.goodsNum }} 件</div>
          </el-form-item>
          <el-form-item label-width="130px" label="退货入库数量">
            <div><el-input v-model="editInWarehouseNumForm.inWarehouseNum" placeholder="请输入退货入库数量"></el-input></div>
          </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button @click="closeEditInWarehouseNumDialog">取消</el-button>
          <el-button type="primary" @click="editInWarehouseNum">确定</el-button>
        </div>
      </el-dialog>

      <el-dialog :visible.sync="imageVisible" width="350px" center>
        <img :src="imageUrl" width="300" />
      </el-dialog>
    </div>
  </div>
</template>

<style lang="less" scoped>
  // .bgc-default{
  //   min-height: calc(100vh - 50px);
  //   box-sizing: border-box;
  // }
  .div-styls{
    margin-top: 30px;
    margin-bottom: 20px;
  }
  .mini-pic {
    width: 68px;
    height: 68px;
    display: block;
    padding: 1px;
    border: #efefef 1px solid;
  }
  .total-in-line{
    line-height: 1.7;
  }
  .total-in-color{
    color: #373737;
  }
  /deep/ .action-table.el-table--medium td{
    padding: 32px 0;
  }
  .title-top{
    border-bottom: #eff1f6 1px solid;
  }
  .buyer-info-line{
    line-height: 2.2;
    height: 300px;
    height: auto!important;
    min-height: 300px;
    overflow: visible;
  }
</style>

<script>
  import { getAfterSale, updateAfterSale, doRejectRefund, doAgreeAfterSale, doSupplierAgreeAfterSale
    , doReceiveGoods, doRefundMoney, addApply, doSaveAfterSaleWarehouse, doEditInWarehouseNum
    , inWarehouseAndAgree, unInWarehouseAndAgree, doConfirmAfterSaleWarehouse
    , checkAfterSaleOperationButtonJurisdiction } from '@/api/after-sale/after-sale'
  import { listAfterSaleReason } from '@/api/after-sale/after-sale-reason'
  import { listProvince, listCity, listDistrict } from '@/api/area/area'
  import { getDictByGroupName } from '@/api/common/common'
  import clipboard from '@/utils/clipboard'
  import elDragDialog from '@/directive/el-dragDialog'
  import { getWarehouse, listWarehouseInfo } from '@/api/warehouse/warehouseInfo'
  import { getByEnterpriseId } from '@/api/user/enterprise'
  import { checkInputNum } from '@/utils/validate'

  export default {
    directives: {
      // 拖动窗口
      elDragDialog
    },
    data() {
      return {
        afterSale: {
          afterSaleType: 10,
          orderStatus: '',
          goodsList: [
            { source: 30 }
          ]
        },
        afterSaleGoodsList: [],
        afterSaleDetail: [],
        afterSaleReasonList: [],
        logList: [],
        afterSaleReasonMap: {},
        dict: {
          orderStatus: {},
          orderType: {},
          afterSaleType: {}
        },
        activeNum: 1,
        editExpressVisible: false,
        editAddressVisible: false,
        editFormVisible: false,
        isEnterpriseRemark: false,
        isSupplierRemark: false,
        isDisagree: false,
        rules: {
          expressName: [
            { required: true, message: '快递名称不能为空', trigger: 'blur' }
          ],
          trackingNo: [
            { required: true, message: '快递单号不能为空', trigger: 'blur' }
          ],
          receiveName: [
            { required: true, message: '收件人名称不能为空', trigger: 'blur' }
          ],
          receivePhone: [
            { required: true, message: '请输入联系电话', trigger: 'blur' },
            { pattern: /^1[0123456789]\d{9}$/, message: '请输入正确的联系电话' }
          ],
          receiveAddress: [
            { required: true, message: '详细地址不能为空', trigger: 'blur' }
          ]
        },
        dialogForm: {
          editText: '',
          expressName: '',
          trackingNo: '',
          receiveName: '',
          receivePhone: '',
          refundProvinceCode: '',
          refundCityCode: '',
          refundDistrictCode: '',
          receiveAddress: '',
          receiveFullAddress: ''
        },
        editAfterSaleWarehouse: false,
        dialogWarehouseForm: {
          afterSaleWarehouseId: '',
          warehouseDetailAddress: '',
          receivePhone: '',
          receiveName: ''
        },
        afterSaleWarehouseList: {},
        provinceList: [],
        cityList: [],
        districtList: [],
        imageUrl: '',
        imageVisible: false,
        listPageAfterSaleStatus: '',
        inWarehouseNumDialog: false,
        editInWarehouseNumForm: {
          goodsNum: '',
          afterSaleGoodsId: '',
          inWarehouseNum: ''
        },
        agreeButtonShow: false,
        disAgreeButtonShow: false,
        agreeRefundGoodsInButtonShow: false,
        agreeRefundGoodsNotInButtonShow: false,
        agreeRefundMoneyShow: false,
        disAgreeRefundMoneyButton: false,
        enableAfterSaleWarehouse: false,
        enterpriseAudit: false,
        saveEditLoading: false,
        freightAmount: ''
      }
    },
    // 初始化页面
    created() {
      listProvince().then(response => {
        if (response.isError) return
        this.provinceList = response.data
      })
      listAfterSaleReason({ enterpriseId: this.getEnterpriseId() }).then(response => {
        if (response.isError) return
        this.afterSaleReasonList = response.data
        this.afterSaleReasonList.forEach(reason => {
          this.afterSaleReasonMap[reason.reasonId] = reason
        })
      })
      if (this.getEnterpriseId()) {
        getByEnterpriseId(this.getEnterpriseId()).then(response => {
          if (response.isError) return
          if (response.data.enableAfterSaleWarehouse === 1) {
            this.enableAfterSaleWarehouse = true
          }
          if (response.data.enterpriseAudit === 1) {
            this.enterpriseAudit = true
          }
        })
      }
      this.init()
    },
    computed: {
      isGroupBuyOrder() {
        return this.afterSale && this.afterSale.projectOrder && this.afterSale.projectOrder.deliveryType
          ? this.afterSale.projectOrder.deliveryType === 3 : false
      },
      // 是否生成配送单号
      isComDeliveryNo() {
        return this.isGroupBuyOrder && this.afterSale && this.afterSale.projectOrder && this.afterSale.projectOrder.deliveryNo &&
          this.afterSale.afterSaleType === 30
      }
    },
    mounted() {
    },
    methods: {
      handleClipboard(text, event) {
        clipboard(text, event)
      },
      init() {
        this.afterSaleDetail = []
        this.afterSaleGoodsList = []
        const afterSaleId = this.getCurrentPage().query.afterSaleId
        this.listPageAfterSaleStatus = this.getCurrentPage().query.afterSaleStatus
        getDictByGroupName('ProjectOrderDTO').then(response => {
          Object.assign(this.dict, response.data)
        })
        getDictByGroupName('AfterSaleDTO').then(response => {
          Object.assign(this.dict, response.data)
        })
        getAfterSale(afterSaleId, this.getSupplierId(), this.getWarehouseId()).then(response => {
          if (response.isError) {
            return
          }
          this.afterSale = response.data
          this.afterSaleDetail.push(this.afterSale)
          this.afterSaleGoodsList = this.afterSale.afterSaleGoodsList
          this.freightAmount = this.afterSale.surplusFreightAmount
          this.logList = this.afterSale.logList
          if (this.afterSale.afterSaleStatus === 0 && !this.afterSale.refundGoodsAmount && (this.getSupplierId() || this.getWarehouseId())) {
            this.afterSale.refundGoodsAmount = this.afterSale.afterSaleGoodsList[0].goodsTotalPrice
          }

          // 售后页面按钮操作权限检查
          checkAfterSaleOperationButtonJurisdiction(afterSaleId, this.getEnterpriseId(), this.getSupplierId(), this.getWarehouseId()).then(response => {
            if (response.isError) {
              return
            }
            // 审核同意
            this.agreeButtonShow = response.data.agreeButton
            // 审核不同意
            this.disAgreeButtonShow = response.data.disAgreeButton
            // 商品入库，同意退款
            this.agreeRefundGoodsInButtonShow = response.data.agreeRefundGoodsButton
            // 商品不入库，同意退款
            this.agreeRefundGoodsNotInButtonShow = response.data.agreeRefundGoodsButton
            // 同意退款
            this.agreeRefundMoneyShow = response.data.agreeRefundMoneyButton
            // 不同意退款
            this.disAgreeRefundMoneyButton = response.data.disAgreeRefundMoneyButton
          })

          switch (this.afterSale.afterSaleStatus) {
            default:
            case 0:
              this.activeNum = 1
              break
            case 1:
              this.activeNum = 2
              break
            case 2:
              if (this.afterSale.afterSaleType === 10) {
                this.activeNum = 3
              } else {
                this.activeNum = 2
              }
              break
            case 3:
            case 4:
            case -3:
            case -2:
            case -1:
              this.activeNum = 4
              break
          }
          if (this.getWarehouseId()) {
            getWarehouse(this.getWarehouseId()).then((response) => {
              if (response.data) {
                // 商品入库，同意退款
                if (response.data.warehouseType === 4) {
                  this.agreeRefundGoodsInButtonShow = false
                }
              }
            })
          }
          // 获取售后仓信息
          if (this.afterSale.afterSaleWarehouseId && this.afterSale.afterSaleWarehouseId !== 1) {
            this.dialogWarehouseForm.afterSaleWarehouseId = this.afterSale.afterSaleWarehouseId ? this.afterSale.afterSaleWarehouseId : ''
            this.getAfterSaleWarehouse(this.dialogWarehouseForm.afterSaleWarehouseId)
          } else {
            this.dialogWarehouseForm.receiveName = ''
            this.dialogWarehouseForm.receivePhone = ''
            this.dialogWarehouseForm.warehouseDetailAddress = ''
          }
        })
        // 获取售后仓库列表
        const data = {
          enterpriseId: this.getEnterpriseId(),
          supplierId: this.getSupplierId(),
          warehouseSource: this.getSupplierId() ? 2 : 1,
          status: 1,
          // 售后仓
          afterSaleWarehouseFlag: 2
        }
        listWarehouseInfo(data).then((response) => {
          this.afterSaleWarehouseList = [{ warehouseId: '1', warehouseName: '(原路退回)' }]
          response.data.forEach(warehouse => {
            this.afterSaleWarehouseList.push({ warehouseId: warehouse.warehouseId, warehouseName: warehouse.warehouseName })
          })
        })
      },
      // 淘宝联盟提交申请
      addApply() {
        addApply(this.afterSale.afterSaleId).then(response => {
          if (response.isError) return
          this.$message({
            type: 'success',
            message: '成功!'
          })
          setTimeout(() => {
            location.reload()
          }, 1000)
        })
      },
      // 供应商/仓库方同意售中取消
      supplierAgreeAfterSale() {
        doSupplierAgreeAfterSale({ afterSaleId: this.afterSale.afterSaleId, supplierId: this.getSupplierId(), warehouseId: this.getWarehouseId() }).then(response => {
          if (response.isError) return
          this.$message({
            type: 'success',
            message: '保存成功!'
          })
          setTimeout(() => {
            location.reload()
          }, 1000)
        })
      },
      // 同意退款
      agreeAfterSale() {
        if (!this.afterSale.refundGoodsAmount) {
          this.$message({ type: 'error', message: '商品退货金额错误' })
          return
        }
        if (this.getSupplierId() || this.getWarehouseId()) {
          this.afterSale.freightAmount = 0
        }
        // if (this.afterSale.afterSaleType * 1 === 10 && (!this.afterSale.receiveAddress || !this.afterSale.receivePhone || !this.afterSale.receiveName ||
        //     !this.afterSale.refundDistrictCode || !this.afterSale.refundCityCode || !this.afterSale.refundProvinceCode)) {
        //   this.$message({ type: 'error', message: '退货地址信息不全' })
        //   return
        // }
        // 退款方
        let auditSupplierId = this.getSupplierId()
        if (!auditSupplierId) {
          auditSupplierId = this.getWarehouseId() ? this.getWarehouseId() : this.getEnterpriseId() ? this.getEnterpriseId() : '0'
        }
        const data = {
          afterSaleId: this.afterSale.afterSaleId,
          refundGoodsAmount: this.afterSale.refundGoodsAmount,
          auditSupplierId: auditSupplierId,
          warehouseId: this.getWarehouseId(),
          supplierId: this.getSupplierId(),
          enterpriseId: this.getEnterpriseId(),
          afterSaleStatus: this.afterSale.afterSaleStatus,
          afterSaleGoodsList: this.afterSaleGoodsList
        }
        // 跨境联盟需要弹窗提示
        if (this.afterSale.crossBorderOrderType === 2) {
          this.$confirm('跨境联盟售后,同意申请将会将相同订单的所有售后单一并同意, 是否继续?', '提示', {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            type: 'warning'
          }).then(() => {
            doAgreeAfterSale(data).then(response => {
              if (response.isError) return
              this.$message({
                type: 'success',
                message: '保存成功!'
              })
              setTimeout(() => {
                location.reload()
              }, 1000)
            })
          }).catch(() => {})
        } else {
          doAgreeAfterSale(data).then(response => {
            if (response.isError) return
            this.$message({
              type: 'success',
              message: '保存成功!'
            })
            setTimeout(() => {
              location.reload()
            }, 1000)
          })
        }
      },
      // 确认收货
      agreeRefundGoods() {
        if (!this.afterSale.refundGoodsAmount) {
          this.$message({ type: 'error', message: '商品退货金额错误' })
          return
        }
        if (!this.afterSale.freightAmount || this.afterSale.freightAmount * 1 < 0) {
          this.$message({ type: 'error', message: '邮费退款金额错误' })
          return
        }
        doReceiveGoods({ afterSaleId: this.afterSale.afterSaleId, refundGoodsAmount: this.afterSale.refundGoodsAmount, freightAmount: this.afterSale.freightAmount }).then(response => {
          if (response.isError) return
          this.$message({
            type: 'success',
            message: '保存成功!'
          })
          setTimeout(() => {
            location.reload()
          }, 1000)
        })
      },
      // 确认退款
      agreeRefundMoney() {
        if (!this.afterSale.refundGoodsAmount) {
          this.$message({ type: 'error', message: '商品退货金额错误' })
          return
        }
        if (!this.afterSale.freightAmount || this.afterSale.freightAmount * 1 < 0) {
          this.$message({ type: 'error', message: '邮费退款金额错误' })
          return
        }
        doRefundMoney({ afterSaleId: this.afterSale.afterSaleId, refundGoodsAmount: this.afterSale.refundGoodsAmount, freightAmount: this.afterSale.freightAmount, payType: this.afterSale.projectOrder.payType }).then(response => {
          if (response.isError) return
          this.$message({
            type: 'success',
            message: '保存成功!'
          })
          setTimeout(() => {
            location.reload()
          }, 1000)
        })
      },
      // 省级下拉联动
      changeProvince(provinceCode) {
        if (!provinceCode) {
          // 改变省份下拉列表时，清空城市，地区下拉列表
          provinceCode = this.dialogForm.refundProvinceCode
          this.dialogForm.refundCityCode = ''
          this.dialogForm.refundDistrictCode = ''
        }
        listCity(provinceCode).then(response => {
          if (response.isError) return
          this.cityList = response.data
        })
      },
      // 市级下拉
      changeCity(cityCode) {
        if (!cityCode) {
          // 改变城市下拉列表时，清空地区下拉列表
          cityCode = this.dialogForm.refundCityCode
          this.dialogForm.refundDistrictCode = ''
        }
        listDistrict(cityCode).then(response => {
          if (response.isError) return
          this.districtList = response.data
        })
      },
      // 打开修改退货仓弹窗, 返回退货仓收货人 联系方式 详细地址
      changeAfterSaleWarehouse() {
        // 获取仓库信息
        this.getAfterSaleWarehouse(this.dialogWarehouseForm.afterSaleWarehouseId)
      },
      // 获取仓库信息
      getAfterSaleWarehouse(afterSaleWarehouseId) {
        if (!afterSaleWarehouseId || afterSaleWarehouseId === 1) {
          this.dialogWarehouseForm.receiveName = ''
          this.dialogWarehouseForm.receivePhone = ''
          this.dialogWarehouseForm.warehouseDetailAddress = ''
          return
        }
        getWarehouse(afterSaleWarehouseId).then((response) => {
          if (response.data) {
            this.dialogWarehouseForm.receiveName = response.data.contact
            this.dialogWarehouseForm.receivePhone = response.data.contactPhone
            this.dialogWarehouseForm.warehouseDetailAddress = response.data.warehouseDetailAddress
          }
        })
      },
      // 不同意退货/退款弹窗
      disAgreeAfterSale() {
        if (this.afterSale.crossBorderOrderType === 2) {
          this.$confirm('跨境联盟售后,不同意申请将会将相同订单的所有售后单一并拒绝, 是否继续?', '提示', {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            type: 'warning'
          }).then(() => {
            this.isEnterpriseRemark = false
            this.isSupplierRemark = false
            this.isDisagree = true
            this.editFormVisible = true
            this.dialogForm.editText = this.afterSale.rejectReason ? this.afterSale.rejectReason : ''
          }).catch(() => {})
        } else {
          this.isEnterpriseRemark = false
          this.isSupplierRemark = false
          this.isDisagree = true
          this.editFormVisible = true
          this.dialogForm.editText = this.afterSale.rejectReason ? this.afterSale.rejectReason : ''
        }
      },
      // 编辑企业备注弹窗
      editEnterpriseRemark() {
        this.isEnterpriseRemark = true
        this.isSupplierRemark = false
        this.isDisagree = false
        this.editFormVisible = true
        this.dialogForm.editText = this.afterSale.enterpriseRemark ? this.afterSale.enterpriseRemark : ''
      },
      // 编辑供应商备注弹窗
      editSupplierRemark() {
        this.isEnterpriseRemark = false
        this.isSupplierRemark = true
        this.isDisagree = false
        this.editFormVisible = true
        this.dialogForm.editText = this.afterSale.supplierRemark ? this.afterSale.supplierRemark : ''
      },
      // 关闭不同意退货/退款弹窗
      cancelEdit() {
        this.editFormVisible = false
        this.isEnterpriseRemark = false
        this.isSupplierRemark = false
        this.isDisagree = false
        this.dialogForm.editText = ''
      },
      // 修改地址弹窗
      showAddress() {
        this.dialogForm.refundProvinceCode = this.afterSale.refundProvinceCode ? this.afterSale.refundProvinceCode : ''
        this.dialogForm.refundCityCode = this.afterSale.refundCityCode ? this.afterSale.refundCityCode : ''
        this.dialogForm.refundDistrictCode = this.afterSale.refundDistrictCode ? this.afterSale.refundDistrictCode : ''
        this.dialogForm.receiveAddress = this.afterSale.receiveAddress ? this.afterSale.receiveAddress : ''
        this.dialogForm.receiveName = this.afterSale.receiveName ? this.afterSale.receiveName : ''
        this.dialogForm.receivePhone = this.afterSale.receivePhone ? this.afterSale.receivePhone : ''
        this.editAddressVisible = true
        if (this.dialogForm.refundProvinceCode) {
          this.changeProvince(this.dialogForm.refundProvinceCode)
        }
        if (this.dialogForm.refundCityCode) {
          this.changeCity(this.dialogForm.refundCityCode)
        }
      },
      // 显示售后仓弹窗
      showAfterSaleWarehouse() {
        this.dialogWarehouseForm.afterSaleWarehouseId = this.afterSale.afterSaleWarehouseId ? this.afterSale.afterSaleWarehouseId : ''
        this.editAfterSaleWarehouse = true
      },
      // 保存修改的地址
      saveAddress() {
        let validateResult = true
        this.$refs.address.validateField(['refundProvinceCode', 'refundCityCode', 'refundDistrictCode', 'receiveAddress', 'receiveName', 'receivePhone'], (valid) => {
          if (valid) {
            validateResult = false
          }
        })
        if (!validateResult) {
          return
        }
        const params = {
          afterSaleId: this.afterSale.afterSaleId,
          refundProvinceCode: this.dialogForm.refundProvinceCode,
          refundCityCode: this.dialogForm.refundCityCode,
          refundDistrictCode: this.dialogForm.refundDistrictCode,
          receiveAddress: this.dialogForm.receiveAddress,
          receiveName: this.dialogForm.receiveName,
          receivePhone: this.dialogForm.receivePhone
        }
        updateAfterSale(params).then(response => {
          if (response.isError) return
          this.$message({
            type: 'success',
            message: '保存成功!'
          })
          getAfterSale(this.afterSale.afterSaleId).then(response => {
            if (response.isError) {
              return
            }
            this.afterSale.receiveFullAddress = response.data.receiveFullAddress
            this.afterSale.refundProvinceCode = response.data.refundProvinceCode
            this.afterSale.refundCityCode = response.data.refundCityCode
            this.afterSale.refundDistrictCode = response.data.refundDistrictCode
            this.afterSale.receiveAddress = response.data.receiveAddress
            this.afterSale.receiveName = response.data.receiveName
            this.afterSale.receivePhone = response.data.receivePhone
            this.editAddressVisible = false
          })
        })
      },
      // 修改退货快递单号弹窗
      showExpress() {
        this.dialogForm.expressName = this.afterSale.expressName ? this.afterSale.expressName : ''
        this.dialogForm.trackingNo = this.afterSale.trackingNo ? this.afterSale.trackingNo : ''
        this.editExpressVisible = true
      },
      // 修改快递
      saveExpress() {
        let validateResult = true
        this.$refs.express.validateField(['expressName', 'trackingNo'], (valid) => {
          if (valid) {
            validateResult = false
          }
        })
        if (!validateResult) {
          return
        }
        updateAfterSale({ afterSaleId: this.afterSale.afterSaleId, expressName: this.dialogForm.expressName, trackingNo: this.dialogForm.trackingNo }).then(response => {
          if (response.isError) return
          this.$message({
            type: 'success',
            message: '保存成功!'
          })
          this.afterSale.expressName = this.dialogForm.expressName
          this.afterSale.trackingNo = this.dialogForm.trackingNo
          this.editExpressVisible = false
        })
      },
      // 不同意退货/退款 || 编辑供应商备注/编辑企业备注
      saveEdit() {
        this.saveEditLoading = true
        // 编辑供应商备注/编辑企业备注
        if (this.isEnterpriseRemark || this.isSupplierRemark) {
          const params = { afterSaleId: this.afterSale.afterSaleId }
          if (this.isEnterpriseRemark) {
            params.enterpriseRemark = this.dialogForm.editText
          }
          if (this.isSupplierRemark) {
            params.supplierRemark = this.dialogForm.editText
          }
          this.saveEditLoading = true
          updateAfterSale(params).then(response => {
            if (response.isError) return
            this.$message({
              type: 'success',
              message: '保存成功!'
            })
            if (this.isEnterpriseRemark) {
              this.afterSale.enterpriseRemark = this.dialogForm.editText
            }
            if (this.isSupplierRemark) {
              this.afterSale.supplierRemark = this.dialogForm.editText
            }
            this.editFormVisible = false
            this.isEnterpriseRemark = false
            this.isSupplierRemark = false
            this.isDisagree = false
          })
        }
        // 不同意退货/退款
        if (this.isDisagree) {
          if (!this.dialogForm.editText) {
            this.$message({ type: 'error', message: '请输入不同意理由！' })
            this.saveEditLoading = false
            return
          }
          let auditSupplierId = this.getSupplierId()
          if (!auditSupplierId) {
            auditSupplierId = this.getWarehouseId() ? this.getWarehouseId() : this.getEnterpriseId() ? this.getEnterpriseId() : '0'
          }
          const data = {
            afterSaleId: this.afterSale.afterSaleId,
            rejectReason: this.dialogForm.editText,
            auditSupplierId: auditSupplierId,
            supplierId: this.getSupplierId(),
            warehouseId: this.getWarehouseId(),
            enterpriseId: this.getEnterpriseId(),
            orderId: this.afterSale.orderId
          }
          doRejectRefund(data).then(response => {
            if (response.isError) return
            this.$message({
              type: 'success',
              message: '保存成功!'
            })
            setTimeout(() => {
              location.reload()
            }, 1000)
          })
        }
      },
      // 关联订单号详情
      goOrderDetail() {
        if (this.getSupplierId()) {
          this.$router.push({ path: '/order/apart-detail', query: { apartOrderId: this.afterSale.afterSaleGoodsList[0].apartOrderId }})
        } else {
          this.$router.push({ path: '/order/order/detail/index', query: { orderId: this.afterSale.orderId }})
        }
      },
      // 返回
      goOrderList() {
        this.$router.go(-1)
      },
      // 退货凭证
      showImage(imageUrl) {
        this.imageUrl = imageUrl
        this.imageVisible = true
      },
      // 保存售后仓
      saveAfterSaleWarehouse() {
        const afterSaleWarehouseId = this.dialogWarehouseForm.afterSaleWarehouseId
        if (!afterSaleWarehouseId) {
          this.$message({ type: 'error', message: '请选择售后仓' })
          return
        }
        doSaveAfterSaleWarehouse({ afterSaleWarehouseId: afterSaleWarehouseId, afterSaleId: this.afterSale.afterSaleId }).then(response => {
          if (response.isError) return
          this.$message({
            type: 'success',
            message: '保存成功!'
          })
          setTimeout(() => {
            location.reload()
          }, 1000)
        })
      },
      // 确认售后仓
      confirmAfterSaleWarehouse() {
        this.$confirm('保存之后将无法再次修改售后仓, 是否继续?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          doConfirmAfterSaleWarehouse({ afterSaleId: this.afterSale.afterSaleId }).then(response => {
            if (response.isError) return
            this.$message({
              type: 'success',
              message: '保存成功!'
            })
            setTimeout(() => {
              location.reload()
            }, 1000)
          })
        }).catch(() => {})
      },
      // 编辑退货入库数量弹窗
      editInWarehouseNumDialog(afterSaleGoodsId, goodsNum) {
        this.inWarehouseNumDialog = true
        this.editInWarehouseNumForm.afterSaleGoodsId = afterSaleGoodsId
        this.editInWarehouseNumForm.goodsNum = goodsNum
      },
      // 关闭退货入库数量弹窗
      closeEditInWarehouseNumDialog() {
        this.inWarehouseNumDialog = false
        this.editInWarehouseNumForm.afterSaleGoodsId = ''
        this.editInWarehouseNumForm.goodsNum = ''
      },
      // 商品入库，同意退款
      agreeRefundGoodsAndGoodsIn() {
        const data = {
          afterSaleId: this.afterSale.afterSaleId,
          supplierId: this.getSupplierId(),
          enterpriseId: this.getEnterpriseId(),
          warehouseId: this.getWarehouseId()
        }
        inWarehouseAndAgree(data).then(response => {
          if (response.isError) return
          this.$message({
            type: 'success',
            message: '保存成功!'
          })
          setTimeout(() => {
            location.reload()
          }, 1000)
        })
      },
      // 商品不入库，同意退款
      disAgreeRefundGoodsAndGoodsIn() {
        const data = {
          afterSaleId: this.afterSale.afterSaleId,
          supplierId: this.getSupplierId(),
          enterpriseId: this.getEnterpriseId(),
          warehouseId: this.getWarehouseId()
        }
        unInWarehouseAndAgree(data).then(response => {
          if (response.isError) return
          this.$message({
            type: 'success',
            message: '保存成功!'
          })
          setTimeout(() => {
            location.reload()
          }, 1000)
        })
      },
      // 保存修改退货入库数量
      editInWarehouseNum() {
        if (!this.editInWarehouseNumForm.inWarehouseNum || this.editInWarehouseNumForm.inWarehouseNum * 1 === 0) {
          this.$message({ type: 'error', message: '退货入库数量错误' })
          return
        }
        if (this.editInWarehouseNumForm.inWarehouseNum > this.editInWarehouseNumForm.goodsNum) {
          this.$message({ type: 'error', message: '退货入库数量不能大于退货商品数量' })
          return
        }
        doEditInWarehouseNum({ afterSaleGoodsId: this.editInWarehouseNumForm.afterSaleGoodsId, inWarehouseNum: this.editInWarehouseNumForm.inWarehouseNum }).then(response => {
          if (response.isError) return
          this.$message({
            type: 'success',
            message: '保存成功!'
          })
          setTimeout(() => {
            location.reload()
          }, 1000)
        })
      },
      // 统计总退款金额
      totalRefundGoodsAmount() {
        var amount = 0
        this.afterSaleGoodsList.some((goods, i) => {
          amount = amount * 1 + goods.goodsRefundMoney * 1
        })
        this.afterSale.refundGoodsAmount = amount
      },
      // 检查运费
      checkFreightAmount(freightAmount) {
        freightAmount = checkInputNum(freightAmount)
        if (!freightAmount || freightAmount * 1 < 0) {
          this.afterSale.freightAmount = this.freightAmount
          this.$message({ type: 'error', message: '未输入邮费退款金额' })
          return
        }
        if (this.freightAmount < freightAmount) {
          this.afterSale.freightAmount = this.freightAmount
          this.$message({ type: 'error', message: '邮费退款金额超过可退款邮费,当前售后设置邮费为: ' + this.freightAmount })
          return
        }
        const params = {
          afterSaleId: this.afterSale.afterSaleId,
          freightAmount: freightAmount,
          refundAmount: this.afterSale.refundGoodsAmount * 1 + freightAmount * 1
        }
        updateAfterSale(params).then(response => {
          if (response.isError) return
          this.$message({
            type: 'success',
            message: '邮费保存成功!'
          })
        })
      }
    }
  }

</script>
